
package org.appfuse.service.impl;

import java.util.List;

import org.appfuse.service.impl.BaseManager;
import org.appfuse.model.Criteria;
import org.appfuse.dao.CriteriaDao;
import org.appfuse.service.CriteriaExistsException;
import org.appfuse.service.CriteriaManager;
import org.springframework.dao.DataIntegrityViolationException;

public class CriteriaManagerImpl extends BaseManager implements CriteriaManager {
    private CriteriaDao dao;

    /**
     * Set the Dao for communication with the data layer.
     * @param dao
     */
    public void setCriteriaDao(CriteriaDao dao) {
        this.dao = dao;
    }

    /**
     * @see org.appfuse.service.CriteriaManager#getCriterias(org.appfuse.model.Criteria)
     */
    public List getCriterias(final Criteria criteria) {
        return dao.getCriterias(criteria);
    }

    /**
     * @see org.appfuse.service.CriteriaManager#getCriteria(String id)
     */
    public Criteria getCriteria(final String id) {
        return dao.getCriteria(new Long(id));
    }

    /**
     * @see org.appfuse.service.CriteriaManager#saveCriteria(Criteria criteria)
     */
    public void saveCriteria(Criteria criteria) throws CriteriaExistsException{
    	try{
        dao.saveCriteria(criteria);
    	}catch(DataIntegrityViolationException e){
    		throw new CriteriaExistsException(" Criteria " + criteria.getCriteriaNumber() + " has already exists.");
    	}
    }
    
    /**
     * @see org.appfuse.service.CriteriaManager#updateCriteria(Criteria criteria)
     */
    public void updateCriteria(Criteria criteria){
        dao.updateCriteria(criteria); 
    }

    /**
     * @see org.appfuse.service.CriteriaManager#removeMenu(String id)
     */
    public void removeCriteria(final String id) {
        dao.removeCriteria(new Long(id));
    }
    
    public List getAllCriterias(){
    	return dao.getAllCriterias();
    }
}
